//
//  HelpLayer.m
//  IconPair
//
//  Created by Yangss on 2010-7-1.
//  Copyright 2010 LotusVille. All rights reserved.


#import "HelpLayer.h"
#import "mainpage.h"

static int sceneIdx=0;
static NSString *transitions[] = {
	@"HelpPage1",
	@"HelpPage2",
};
#define	PAGECOUNT	(sizeof(transitions) / sizeof(transitions[0]))

Class nextAction()
{
	sceneIdx++;
	if (sceneIdx > PAGECOUNT-1) {
		sceneIdx = PAGECOUNT-1;
		return nil;
	}	
	NSString *r = transitions[sceneIdx];
	Class c = NSClassFromString(r);
	return c;
}

Class backAction()
{
	sceneIdx--;
	if (sceneIdx < 0) {
		sceneIdx = 0;
		return nil;
	}
	NSString *r = transitions[sceneIdx];
	Class c = NSClassFromString(r);
	return c;
}

//帮助页1
@implementation HelpPage1
-(void) onEnter
{
	[super onEnter];
		
	//tamara.opacity = 0;
	id action1 = [CCMoveTo actionWithDuration:0.5f position:ccp(320, 480)];
	id action2 = [CCFadeIn actionWithDuration:1.0f];
	

	[spHelpBg02 runAction: [CCSequence actions: action1, nil]];
	[spHelpBg01 runAction: [CCSequence actions: action2, nil]];
}
@end

//帮助页2
@implementation HelpPage2
-(void) onEnter
{
	[super onEnter];
	
	//tamara.opacity = 0;
	id action1 = [CCMoveTo actionWithDuration:0.5f position:ccp(-320, -480)];
	id action2 = [CCFadeIn actionWithDuration:1.0f];

	[spHelpBg01 runAction: [CCSequence actions: action1, nil]];
	[spHelpBg02 runAction: [CCSequence actions: action2, nil]];
}
@end


@implementation HelpLayer
-(id) init{
	self = [super init];
	if (!self) {
		return nil;
	}

	//排行榜背景图
	spHelpBg01 = [[CCSprite spriteWithFile:@"helpBg01.png"] retain];
	spHelpBg01.anchorPoint = CGPointZero;
	[self addChild:spHelpBg01 z:1 tag:1];
		
	spHelpBg02 = [[CCSprite spriteWithFile:@"helpBg02.png"] retain];
	spHelpBg02.anchorPoint = CGPointZero;
	[self addChild:spHelpBg02 z:0 tag:2];
	
	[CCMenuItemFont setFontName: @"Marker Felt"];
	[CCMenuItemFont setFontSize:28];
	
	//back按钮
	CCSprite * spBack = [CCSprite spriteWithFile:@"back.png"];
	CCMenuItem * miBack = [CCMenuItemSprite itemFromNormalSprite:spBack selectedSprite:spBack target:self selector:@selector(backCallback:)];
	CCMenu *menuBack = [CCMenu menuWithItems:miBack, nil];
	menuBack.position = ccp(60,30);
	[self addChild:menuBack z:2];
	
	//next按钮
	CCSprite * spNext = [CCSprite spriteWithFile:@"next.png"];
	CCMenuItem * miNext = [CCMenuItemSprite itemFromNormalSprite:spNext selectedSprite:spNext target:self selector:@selector(nextCallback:)];
	CCMenu *menuNext = [CCMenu menuWithItems:miNext, nil];
	menuNext.position = ccp(270,30);
	[self addChild:menuNext z:2];
	
	//menu按钮
	CCSprite * spMenu = [CCSprite spriteWithFile:@"menu.png"];
	CCMenuItem * miMenu = [CCMenuItemSprite itemFromNormalSprite:spMenu selectedSprite:spMenu target:self selector:@selector(mainmenuCallback:)];
	CCMenu *menuMenu = [CCMenu menuWithItems:miMenu, nil];
	menuMenu.position = ccp(160,40);
	[self addChild:menuMenu z:2];

	return self;
}

//menu按钮回调函数
-(void) mainmenuCallback: (id) sender
{
	CCScene *sc = [CCScene node];
	[sc addChild:[mainpage node]];
	
	[[CCDirector sharedDirector] replaceScene:  [CCZoomFlipYTransition transitionWithDuration:0.5f scene:sc]];	
	//	[[CCDirector sharedDirector] popScene];
}

//next按钮回调函数
-(void) nextCallback: (id) sender
{
	CCScene *s = [CCScene node];
	Class c = nextAction();
	if (c!=nil) {
		[s addChild: [c node]];
		//	[s addChild: [nextAction() node]];
		[[CCDirector sharedDirector] replaceScene: s];
	}
}

//back按钮回调函数
-(void) backCallback: (id) sender
{
	CCScene *s = [CCScene node];
	Class c = backAction();
	if (c!=nil) {
		[s addChild: [c node]];
		[[CCDirector sharedDirector] replaceScene: s];
	}
}

@end



